package com.spica.spicaschool.viewmodel

import androidx.lifecycle.LiveData
import com.spica.spicaschool.base.LiveCoroutinesViewModel
import com.spica.spicaschool.bean.newsdetail.NewsDetail
import com.spica.spicaschool.network.repository.NewsDetailRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class NewsDetailViewModel @Inject constructor(
    private val newsDetailRepository: NewsDetailRepository
) : LiveCoroutinesViewModel() {


    private lateinit var _newsDetailLiveData: LiveData<NewsDetail>


    val newsLiveData: LiveData<NewsDetail>
        get() = _newsDetailLiveData


    fun fetchNewsDetail(
        id: String,
        onStart: () -> Unit,
        onComplete: () -> Unit,
        onError: (String?) -> Unit
    ) {
        _newsDetailLiveData = newsDetailRepository.fetchNewsDetail(id, onStart, onComplete, onError)
            .asLiveDataOnViewModelScope()
    }


}